package com.br.android.widing.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteQuery;

public class WidingGanhoCursor extends SQLiteCursor {

	public static final String QUERY = "SELECT * FROM ganho ORDER BY idganho DESC";
	public static final String QUERY_SOMA_VALORES = "SELECT SUM(valorganho) AS soma_valores from ganho";
	public static final String QUERY_SOMA_VALORES_POR_CATEGORIA = "SELECT categoriaganho, SUM(valorganho) AS valor_por_categoria FROM ganho GROUP BY categoriaganho";
	
	public WidingGanhoCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
	}

	public static class Factory implements CursorFactory {

		@Override
		public Cursor newCursor(SQLiteDatabase db,
				SQLiteCursorDriver masterQuery, String editTable,
				SQLiteQuery query) {
			return new WidingGanhoCursor(db, masterQuery, editTable, query);
		}
	}
	
	public int getIdGanho(){
		return getInt(getColumnIndexOrThrow("idganho"));
	}
	
	public String getNomeGanho(){
		return getString(getColumnIndexOrThrow("nomeganho"));
	}
	
	public double getValorGanho(){
		return getDouble(getColumnIndexOrThrow("valorganho"));
	}
	
	public String getCategoriaGanho(){
		return getString(getColumnIndexOrThrow("categoriaganho"));
	}
	
	public String getDataGanho(){
		return getString(getColumnIndexOrThrow("dataganho"));
	}
	
	public double getSomaValores(){
		return getDouble(getColumnIndexOrThrow("soma_valores"));
	}
	
	public double getValorPorCategoria(){
		return getDouble(getColumnIndexOrThrow("valor_por_categoria"));
	}
	
}
